<?php namespace Summer\Userhub\Updates;

use Schema;
use Winter\Storm\Database\Updates\Migration;

class UserAddBankFields extends Migration
{
    public function up()
    {
        if (Schema::hasColumns('users', [
            'bank_name',
            'bank_number',
            'bank_address',
            'wechat_number',
            'alipay_number',
        ])) {
            return;
        }

        Schema::table('users', function($table)
        {
            $table->string('bank_name')->nullable();//开户银行
            $table->string('bank_number')->nullable();//银行卡号
            $table->string('bank_address')->nullable();//开户地址
            $table->string('wechat_number')->nullable();//收款微信号
            $table->string('alipay_number')->nullable();//收款支付宝号
        });
    }

    public function down()
    {
        if (Schema::hasTable('users')) {
            Schema::table('users', function ($table) {
                $table->dropColumn([
                    'bank_name',
                    'bank_number',
                    'bank_address',
                    'wechat_number',
                    'alipay_number',
                ]);
            });
        }
    }
}
